package com.open.base.model;

import com.alibaba.fastjson2.JSON;
import com.open.common.enums.ConfigEnum;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author dashu
 * @date 2025/1/20 0:12
 * @description
 */
@ConfigurationProperties(prefix = "spring.datasource")
@Component("dataSourceDefault")
public class DataSource extends BaseUserConfig {
    private String driver;
    private String url;
    private String username;
    private String password;

    // 添加特殊 setter 方法
    public void setDriverClassName(String driver) {
        this.driver = driver;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String getConfigType() {
        return ConfigEnum.DataBase.type;
    }

    @Override
    protected Object parseConfig(String configJson) {
        return JSON.parseObject(configJson, DataSource.class);
    }

    @Override
    protected Object getDefaultInstance() {
        // 返回当前实例作为默认配置
        return this;
    }
}
